package com.superdaxue.rxsampledemo.utils;

import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;

/**
 * Created by ZX_CC on 2016/4/20.
 */

public class RecyclerHolder extends RecyclerView.ViewHolder {
    private final SparseArray<View> viewDatas;

    public RecyclerHolder(View itemView) {
        super(itemView);
        this.viewDatas = new SparseArray<>(8);
    }

    public SparseArray<View> getAllView() {
        return viewDatas;
    }

    public <T extends View> T getView(int resId) {
        View view = viewDatas.get(resId);
        if (view == null) {
            view = itemView.findViewById(resId);
            viewDatas.put(resId, view);
        }
        return (T) view;
    }



    public RecyclerHolder setText(int viewId, String text) {
        TextView view = getView(viewId);
        if (view != null) {
            view.setText(text);
        }
        return this;
    }
}
